import axios from "./config"

// get
export function get(url, data=null) {
    return new Promise((resolve, reject) => {
        axios.get(url, {params: data})
            .then(res => resolve(res.data))
            .catch(err => reject(err))
    })
}

// post
// 默认 json 格式，封装成 表单格式的
export function post(url, data={}, config={}) {
    return new Promise((resolve, reject) => {
        axios.post(url, data, {
            headers: config
        })
            .then(res => resolve(res.data))
            .catch(err => reject(err))
    })
}

// put
export function put(url, data=null, config={}) {
    return new Promise((resolve, reject) => {
        axios.put(url, data, {
            headers: config
        })
            .then(res => resolve(res.data))
            .catch(err => reject(err))
    })
}

// delete
export function _delete(url, data=null, config={}) {
    return new Promise((resolve, reject) => {
        axios.delete(url, data, {
            headers: config
        })
            .then(res => resolve(res.data))
            .catch(err => reject(err))
    })
}
